<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class FmwYouZanController extends Controller
{
    protected $baseUrl = '/api/youzan/';

    protected $authority_id = '90694529';

    /**
     * @return string
     */
    private function _generateTraceId()
    {
        return sprintf("%s-%s", date('YmdHis'), Str::random(10));
    }

    public function index(Request $request)
    {
        $urlArgs = explode('/', str_replace($this->baseUrl, '', $request->getRequestUri()));
        if (empty($urlArgs) || empty($urlArgs[0])) {
            return [];
        }
        $method = str_replace('.', '_', $urlArgs[0]);

        if (!method_exists($this, $method)) {
            echo sprintf("[%s] mock function not exists", $method);
            exit;
        }

        return $this->$method($request);
    }

    protected function token()
    {
        $expires = sprintf("%s%s", time(), rand(100, 999));
        return [
            "success" => true,
            "code" => 200,
            "data" => [
                "expires" => (int)$expires,
                "scope" => "beauty_appointment beauty_cashier beauty_item beauty_member ",
                "access_token" => Str::random(10) . "8db2aa65d38bf5de710b",
                "authority_id" => $this->authority_id,
                "refresh_token" => Str::random(10) . "cba63a7044b64d5w9603"
            ],
            "message" => null
        ];
    }

    /**
     * 批量解密收件人信息
     * @param Request $request
     * @return array
     */
    protected function youzan_cloud_secret_decrypt_batch(Request $request)
    {
        $sources = $request->get('sources', []);
        if (empty($sources)) {
            return [
                'code' => 10500,
                'success' => false,
                'trace_id' => $this->_generateTraceId(),
            ];
        }

        if (count($sources) == 3) {
            $data = [
                $sources[0] => sprintf('收货地址-通州万达-%s', Str::random(5)),
                $sources[1] => sprintf('收件人%s', Str::random(3)),
                $sources[2] => sprintf('1330%s011', rand(100, 999)),
            ];
        } else {
            $data = [];
            foreach (array_chunk($sources, 5) as $chuckSources) {
                $data[$chuckSources[0]] = sprintf('buyer_name-%s', Str::random(5));
                $data[$chuckSources[1]] = sprintf('1330%s011', rand(100, 999));
                $data[$chuckSources[2]] = sprintf('receiver_name-%s', Str::random(5));
                $data[$chuckSources[3]] = sprintf('收货地址-通州万达-%s', Str::random(3));
                $data[$chuckSources[4]] = sprintf('1330%s011', rand(100, 999));
            }
        }

        return [
            'code' => 200,
            'success' => true,
            'message' => 'successful',
            'trace_id' => $this->_generateTraceId(),
            'data' => $data
        ];
    }

    /**
     * 获取单个订单数据
     * @param Request $request
     * @return array
     */
    protected function youzan_trade_get(Request $request)
    {
        $string = '{"trace_id":"yz7-0ae85be5-1736409112451-223347","code":200,"data":{"delivery_order":[{"express_state":1,"oids":[{"oid":"3050166623027986566"},{"oid":"3050166623027986567"}],"express_type":0,"dists":[{"dist_items":[{"oid":"3050166623027986566"},{"oid":"3050166623027986567"}],"dist_id":"202412251726160000230746","express_info":{"express_id":3,"express_no":"78867490641876"}}]}],"order_promotion":{"item":[],"adjust_fee":"0.00","order_paid_promotion":[],"order":[]},"refund_order":[],"full_order_info":{"child_info":{"child_orders":[]},"remark_info":{"buyer_message":""},"address_info":{"self_fetch_info":"","delivery_address":"$kH2S855GyCFqYBj7YtuU0ebrN/ZxQjxgbo10HzPPBQUv+6lmiQYt64xBDee4Zaddb9oLdfNxcxBolfKVzzPVSg==$2$","delivery_postal_code":"200050","receiver_name":"$iolqOzJcs5IkjrxMmIlawg==$2$","delivery_province":"上海市","delivery_city":"上海市","delivery_district":"长宁区","address_extra":"{\"areaCode\":\"310105\",\"lon\":121.39965737814461,\"lat\":31.200656759189254}","receiver_tel":"$HyO5lJSgfL/UiCqtS9bMyw==$2$"},"pay_info":{"outer_transactions":["4200002448202412251468495522"],"deduction_real_pay":87717,"real_payment":"877.17","post_fee":"0.00","deduction_pay":0,"phase_payments":[],"total_fee":"804.00","payment":"877.17","transaction":["2412251431582623340991"]},"buyer_info":{"outer_user_id":"o85dx5SqSv_hal5VTUBYtZz4OoyI","buyer_phone":"$HyO5lJSgfL/UiCqtS9bMyw==$2$","yz_open_id":"XkPBKn88708885751982522368","fans_type":549751,"fans_nickname":"$+m1gVrT7p7NWFTgrX7+VCg==$2$","fans_id":21419433933},"orders":[{"goods_total_dutiable_price":"438.00","is_cross_border":"1","item_type":0,"discount_price":"146.00","goods_date":"","num":3,"price":"146.00","sub_order_no":"E202412251431570746061511210NN","total_fee":"438.00","fenxiao_price":"0.00","payment":"477.87","item_barcode":"","outer_sku_id":"4976561759991","goods_url":"https://h5.youzan.com/v2/showcase/goods?alias=2g4kwnb4edwfwcc","is_price_calendar":"","virtual_currency":"0.00","weight":"","sku_id":14792834939,"sku_properties_name":"[{\"k\":\"适用发质\",\"k_id\":56434,\"v\":\"稀疏发质\",\"v_id\":545213234}]","promotion_discount":"0.00","outer_oid":"","points_price":"0","tariff_rule":"0","root_item_id":"0","sku_barcode":"","item_props":"[]","tax_total":"39.87","outer_item_id":"","warehouse_code":"","freight":"0.00","goods_dutiable_price":"146.00","oid":"3050166623027986566","goods_snapshot":"https://h5.youzan.com/wscgoods/detail-snapshot?alias=2g4kwnb4edwfwcc&pageType=wsc-goods-snapshot&kdtId=165292092&orderNo=E20241225143157074606151&goodsId=3550820193&snapKey=3c095e577aad394d7aafea5ba79d8ca7&itemId=3050166623027986566","title":"La CASTA蕾珂诗 日本沙龙级洗头梳子头皮预洗梳深层清洁按摩护理","fenxiao_payment":"0.00","item_no":"","buyer_messages":"{}","root_sku_id":"","is_present":false,"cross_border_trade_mode":"1210","haitao_discount":"0.00","sale_plan":{"penalty":{},"cancel_rule_time":{}},"alias":"2g4kwnb4edwfwcc","is_pre_sale":"","sku_unique_code":"355082019314792834939","customs_code":"NN","item_id":3550820193,"pic_path":"https://img01.yzcdn.cn/upload_files/2024/11/08/FlJphDKnR1qLUcAi1O2-MvLxki0k.jpg","pre_sale_type":"","sku_no":"4976561759991"},{"goods_total_dutiable_price":"366.00","is_cross_border":"1","item_type":0,"discount_price":"183.00","goods_date":"","num":2,"price":"183.00","sub_order_no":"E202412251431570746061511210NN","total_fee":"366.00","fenxiao_price":"0.00","payment":"399.30","item_barcode":"","outer_sku_id":"4976561759267","goods_url":"https://h5.youzan.com/v2/showcase/goods?alias=26urftzsk97os63","is_price_calendar":"","virtual_currency":"0.00","weight":"","sku_id":25715794986,"sku_properties_name":"[{\"k\":\"适用发质\",\"k_id\":56434,\"v\":\"稀疏扁塌发质\",\"v_id\":545214240}]","promotion_discount":"0.00","outer_oid":"","points_price":"0","tariff_rule":"0","root_item_id":"0","sku_barcode":"","item_props":"[]","tax_total":"33.30","outer_item_id":"","warehouse_code":"","freight":"0.00","goods_dutiable_price":"183.00","oid":"3050166623027986567","goods_snapshot":"https://h5.youzan.com/wscgoods/detail-snapshot?alias=26urftzsk97os63&pageType=wsc-goods-snapshot&kdtId=165292092&orderNo=E20241225143157074606151&goodsId=3551134934&snapKey=f7bbea577f4fe2ef326a725852b88be6&itemId=3050166623027986567","title":"La CASTA 蕾珂诗 日本进口专业沙龙级头发养护气垫梳子  清洁蓬松 SPA按摩梳","fenxiao_payment":"0.00","item_no":"","buyer_messages":"{}","root_sku_id":"","is_present":false,"cross_border_trade_mode":"1210","haitao_discount":"0.00","sale_plan":{"penalty":{},"cancel_rule_time":{}},"alias":"26urftzsk97os63","is_pre_sale":"","sku_unique_code":"355113493425715794986","customs_code":"NN","item_id":3551134934,"pic_path":"https://img01.yzcdn.cn/upload_files/2024/11/08/Fs_dD0M4agikfOiQEnLbdZOyuRoH.jpg","pre_sale_type":"","sku_no":"4976561759267"}],"source_info":{"order_source_code":"merchant_xcx","is_offline_order":false,"book_key":"c60bb5b4-c13d-44ab-8c38-f1440cfbb7cd","order_source":"微信-商家小程序","biz_source":"","source":{"platform":"other","wx_entrance":"merchant_xcx"},"order_mark":"wx_shop"},"order_info":{"consign_time":"2024-12-25 17:26:16","order_extra":{"is_from_cart":"true","id_card_name":"$iolqOzJcs5IkjrxMmIlawg==$2$","id_card_back_photo":"","buyer_name":"$+m1gVrT7p7NWFTgrX7+VCg==$2$","salesman":{"salesman_mobile":"13611703171","salesman_nick_name":"伊藤"},"force_consignment_mode":"0","marketing_channel":"directSeller","id_card_number":"$yTCNtKmaoJJr3U7CgMx7Ez4ErRyJEsDMOoBiTt6DRQI=$2$","is_points_order":"0","id_card_front_photo":""},"expired_time":"2024-12-25 15:31:58","type":0,"tid":"E202412251431570746000001","node_kdt_id":165292092,"update_time":"2025-01-01 17:26:36","pay_type_str":"WEIXIN_DAIXIAO","pay_type":10,"team_type":0,"channel_type":0,"created":"2024-12-25 14:31:58","status_str":"已完成","success_time":"2025-01-01 17:26:16","shop_name":"克瑞斯健康商城","confirm_time":"","pay_time":"2024-12-25 14:32:08","is_retail_order":false,"pay_type_desc":"微信支付","backstage_order_type":"CROSS_BORDER","refund_state":0,"root_kdt_id":165292092,"close_type":0,"status":"WAIT_SELLER_SEND_GOODS","express_type":0,"order_tags":{"is_member":true,"is_secured_transactions":true,"is_settle":true,"is_payed":true}}}},"success":true,"message":"successful"}';
        return json_decode($string, true);

        $tid = $request->get('tid', '');

        if (empty($tid)) {
            return [
                'code' => 5000,
                'success' => false,
                'data' => [
                    "delivery_order" => [],
                    "refund_order" => [],
                    "order_promotion" => [
                        "item" => [],
                        "order_paid_promotion" => [],
                        "order" => []
                    ],
                    "full_order_info" => [
                        "child_info" => [
                            "child_orders" => []
                        ],
                        "pay_info" => [
                            "phase_payments" => []
                        ],
                        "orders" => []
                    ],
                ],
                'message' => 'trade not found',
                'trace_id' => $this->_generateTraceId(),
            ];
        }

        // WAIT_BUYER_PAY：等待买家付款，定金预售描述：定金待付、等待尾款支付开始、尾款待付
        // TRADE_PAID：订单已支付 ，该状态仅代表当前订单已支付成功，表示瞬时状态，稍后会自动修改成后面的状态。如果不关心此状态请再次请求详情接口获取下一个状态
        // WAIT_CONFIRM：待确认，包含待成团、待接单等等。即：买家已付款，等待成团或等待接单
        // WAIT_SELLER_SEND_GOODS：等待卖家发货，即：买家已付款
        // WAIT_BUYER_CONFIRM_GOODS 等待买家确认收货，即：卖家已发货
        // TRADE_SUCCESS：买家已签收以及订单成功
        // TRADE_CLOSED：交易关闭

        $orderStatus = 'WAIT_SELLER_SEND_GOODS';
        $oid = '2911389267541884972';
        $adjustFee = 0.00;
        $postFee = 10.00;
        $orderDiscountFee = 1.00;
        $itemDiscountFee = 10.00;

        $productTotalFee = 100.00;
        // 100 + 10 - 10
        $orderTotalFee = $productTotalFee + $postFee - $itemDiscountFee;
        // 100 + 10 - 10 - 1 - 1
        $paymentFee = $productTotalFee + $postFee - $adjustFee - $itemDiscountFee - $orderDiscountFee;

        $promotionItem = [
            "is_present" => false,
            "promotions" => [[
                "promotion_type" => "customerDiscount",
                "promotion_title" => "会员折扣",
                "card_no" => "",
                "promotion_type_name" => "会员折扣",
                "promotion_id" => 309192,
                "promotion_type_id" => 10,
                "discount_fee" => $itemDiscountFee
            ]],
            "item_id" => 441056041,
            "sku_id" => 4823115412985,
            "oid" => $oid
        ];

        $promotionOrder = [
            "promotion_type" => "coupon",
            "item_info" => [[
                "oid" => $oid,
                "discount_fee" => $orderDiscountFee
            ]],
            "sub_promotion_type" => "card",
            "promotion_title" => "ys随机",
            "coupon_id" => "4071296240",
            "promotion_condition" => "满任意金额可用",
            "promotion_type_name" => "优惠卡券",
            "promotion_content" => "",
            "promotion_id" => 33539353,
            "discount_fee" => $orderDiscountFee,
            "promotion_type_id" => 105
        ];

        return [
            "code" => 200,
            "data" => [
                "delivery_order" => [],
                "refund_order" => [],
                "order_promotion" => [
                    "adjust_fee" => $adjustFee,
                    "order_discount_fee" => $orderDiscountFee,
                    "item_discount_fee" => $itemDiscountFee,
                    "order_paid_promotion" => [],
                    "item" => [$promotionItem],
                    "order" => [$promotionOrder]
                ],
                "full_order_info" => [
                    "child_info" => [
                        "child_orders" => []
                    ],
                    "remark_info" => [
                        "buyer_message" => "",
                    ],
                    "address_info" => [
                        "self_fetch_info" => "",
                        "delivery_address" => "test_delivery_address",
                        "delivery_postal_code" => "",
                        "receiver_name" => "fmw_api_mock_receiver_name",
                        "delivery_province" => "浙江省",
                        "delivery_city" => "杭州市",
                        "delivery_district" => "西湖区",
                        "address_extra" => "{\"areaCode\" =>\"330106\",\"lon\" =>120.09320949491782,\"lat\" =>30.262507397212282}",
                        "receiver_tel" => "18800000011"
                    ],
                    "pay_info" => [
                        "outer_transactions" => [],
                        "deduction_real_pay" => 0,
                        "real_payment" => $paymentFee,
                        "post_fee" => $postFee,
                        "deduction_pay" => 0,
                        "phase_payments" => [],
                        "total_fee" => $productTotalFee,
                        "payment" => $paymentFee,
                        "transaction" => []
                    ],
                    "buyer_info" => [
                        "outer_user_id" => "",
                        "buyer_phone" => "13011110002",
                        "yz_open_id" => "c0AZLuGL686957154271236096",
                        "fans_type" => 0,
                        "fans_nickname" => "nickName",
                        "fans_id" => 0
                    ],
                    "orders" => [[
                        "is_cross_border" => "",
                        "outer_item_id" => "P221207653249166",
                        "item_type" => 0,
                        "discount_price" => $orderDiscountFee,
                        "goods_date" => "",
                        "warehouse_code" => "",
                        "num" => 1,
                        "oid" => $oid,
                        "goods_snapshot" => "https =>//h5.youzan.com/wscgoods/detail-snapshot?alias=275djqzmofu96nm&pageType=wsc-goods-snapshot&kdtId=62035306&orderNo=E20221208154313072702024&goodsId=441056041&snapKey=6e09d61b2bf35b3e132139f05f97959e,bd3fa95599a990731cbba2ad06e27019&itemId=2911389267541884972",
                        "title" => "ys商品无分组",
                        "fenxiao_payment" => "0.00",
                        "item_no" => "BM221207920473342",
                        "buyer_messages" => "",
                        "root_sku_id" => "4823115412985",
                        "is_present" => false,
                        "cross_border_trade_mode" => "",
                        "price" => $productTotalFee,
                        "sub_order_no" => "",
                        "total_fee" => $orderTotalFee,
                        "fenxiao_price" => "0.00",
                        "sale_plan" => [
                            "penalty" => [],
                            "cancel_rule_time" => []
                        ],
                        "alias" => "275djqzmofu96nm",
                        "payment" => $paymentFee - $postFee,
                        "item_barcode" => "P221207653249166",
                        "is_pre_sale" => "",
                        "outer_sku_id" => "P221207653249166",
                        "sku_unique_code" => "",
                        "goods_url" => "https =>//h5.youzan.com/v2/showcase/goods?alias=275djqzmofu96nm",
                        "customs_code" => "",
                        "is_price_calendar" => "",
                        "item_id" => 441056041,
                        "weight" => "",
                        "sku_id" => 0,
                        "sku_properties_name" => "[]",
                        "pic_path" => "https =>//img.yzcdn.cn/upload_files/2020/05/19/FhO5Y19m1QWzD_FXF3lxF8IllIgN.png",
                        "shop_org_id" => "",
                        "outer_oid" => "",
                        "pre_sale_type" => "",
                        "points_price" => "0",
                        "sku_no" => "",
                        "root_item_id" => "441056034",
                        "sku_barcode" => "P221207653249166",
                        "item_props" => "[]"
                    ]],
                    "source_info" => [
                        "is_offline_order" => false,
                        "book_key" => "7e22d7c5-8cd3-4d07-b1b5-3d6456486dd1",
                        "biz_source" => "",
                        "source" => [
                            "platform" => "browser",
                            "wx_entrance" => "direct_buy"
                        ]
                    ],
                    "order_info" => [
                        "consign_time" => "",
                        "created" => "2022-12-08 15:43:13",
                        "expired_time" => "2022-12-08 16:43:13",
                        "status_str" => "待发货",
                        "success_time" => "",
                        "type" => 0,
                        "shop_name" => "fmw_api_mock_shop_name",
                        "tid" => $tid,
                        "confirm_time" => "",
                        "pay_time" => "2022-12-08 15:43:15",
                        "node_kdt_id" => 62035306,
                        "update_time" => date('Y-m-d H:i:s'),
                        "pay_type_str" => "COUPONPAY",
                        "is_retail_order" => true,
                        "pay_type" => 16,
                        "team_type" => 7,
                        "channel_type" => 0,
                        "refund_state" => 0,
                        "root_kdt_id" => 62035302,
                        "close_type" => 0,
                        "status" => $orderStatus,
                        "express_type" => 2,
                        "order_extra" => [
                            "is_from_cart" => "false",
                            "buyer_name" => "buyerName",
                            "force_consignment_mode" => "0",
                            "is_points_order" => "0",
                            "retail_pick_up_code" => "24002"
                        ],
                        "order_tags" => [
                            "is_member" => true,
                            "is_secured_transactions" => true,
                            "is_payed" => true,
                            "is_purchase_order" => false,
                        ]
                    ]
                ],
            ],
            "success" => true,
            "message" => "successful",
            "trace_id" => $this->_generateTraceId(),
        ];
    }

    protected function youzan_trade_refund_get(Request $request)
    {
        $refundId = $request->get('refund_id', '');
        if (empty($refundId)) {
            return [
                "data" => [
                    "refund_order_item" => [],
                    "consult_message" => [],
                    "refund_fund_list" => []
                ],
                "code" => 103010054,
                "success" => false,
                "message" => "查询的店铺ID不符合当前退款单的查询权限",
                "trace_id" => $this->_generateTraceId(),
            ];
        }

        // BUYER_APPLY_REFUND(买家申请退款)
        // SELLER_REFUND（商家主动退款）
        // EXCHANGE_GOODS(买家申请换货)
        // SYSTEM_REFUND（一键退款，特殊类型退款。如超卖，支付回调超时）
        $refundType = 'BUYER_APPLY_REFUND';
        $demand = 1; // 1.仅退款；2.退货退款；3.换货

        // WAIT_SELLER_AGREE-买家已经申请退款，等待卖家同意;
        // WAIT_BUYER_RETURN_GOODS-卖家已经同意退款，等待买家退货;
        // WAIT_SELLER_CONFIRM_GOODS-买家已经退货，等待卖家确认收货;
        // SELLER_REFUSE_BUYER-卖家拒绝退款;
        // SELLER_REFUSE_BUYER_RETURN_GOODS-卖家未收到货,拒绝退款 ;
        // SELLER_RETURN_GOODS-商家确认收货并发送换货;
        // CLOSED-退款关闭;
        // SUCCESS-退款成功;
        $returnGoods = false;
        $refundStatus = 'SUCCESS';

        $prefix = '10';
        $suffix = '002';
        $tid = substr($refundId, strlen($prefix), strlen($refundId) - strlen($prefix) - strlen($suffix));

        $refundFee = 1.00;
        $refundPostage = 0.00;
        $kdtId = 20230112111;
        $oid = 2911389267541884972;
        $itemId = 441056041;

        return [
            "code" => 200,
            "data" => [
                "reason" => 54,
                "refund_type" => $refundType,
                "demand_desc" => "仅退款",
                "item_id" => $itemId,
                "created" => date('Y-m-d H:i:s'),
                "consult_message" => [],
                "oid" => $oid,
                "version" => time(),
                "demand" => $demand,
                "refund_id" => $refundId,
                "tid" => $tid,
                "item_num" => 1,
                "refund_fund_list" => [[
                    "refund_mode" => 0,
                    "refund_fee" => $refundFee,
                    "refund_no" => "202104141012400020500512",
                    "message" => "退款成功",
                    "refund_id" => "202104141012060020350512",
                    "pay_way" => 28,
                    "status" => 2
                ]],
                "refund_order_item" => [[
                    "kdt_id" => $kdtId,
                    "refund_fee" => $refundFee,
                    "oid" => $oid,
                    "item_num" => 1
                ]],
                "kdt_id" => $kdtId,
                "refund_postage" => $refundPostage,
                "return_goods" => $returnGoods,
                "refund_fee" => $refundFee,
                "refund_account_time" => date('Y-m-d H:i:s'),
                "modified" => date('Y-m-d H:i:s'),
                "cs_status" => 1,
                "refund_fund_desc" => "根据买家的支付方式，资金将原路退回到买家的支付账户。退款将返还实际入账金额，免充值的支付优惠金额将从退款金额中扣除。",
                "status" => $refundStatus,
                "desc" => ""
            ],
            "success" => true,
            "message" => "successful",
            "trace_id" => $this->_generateTraceId(),
        ];
    }

    protected function youzan_logistics_waybill_get_template(Request $request)
    {
        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId(),
            "data" => [
                [
                    "template_name" => "韵达快递标准模板",
                    "template_url" => "http://cloudprint.cainiao.com/template/standard/401/198",
                    "express_id" => 4
                ],
                [
                    "template_name" => "圆通快递标准模板",
                    "template_url" => "http://cloudprint.cainiao.com/template/standard/101/635",
                    "express_id" => 2
                ],
            ]
        ];
    }

    protected function youzan_logistics_waybill_query_netsite(Request $request)
    {
        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId(),
            "data" => [
                [
                    "express_id" => 4,
                    "payment_type" => 1,
                    "need_customer_code" => false,
                    "all_type" => [1],
                    "lattice_point_detail_model" => [
                        [
                            "brand_code" => "",
                            "delivery_address_models" => [],
                            "lattice_point_name" => "浙江杭州玉泉公司",
                            "lattice_point_no" => "310020",
                            "brand_name" => "",
                            "lattice_point_account_models" => [],
                        ],
                        [
                            "brand_code" => "",
                            "delivery_address_models" => [],
                            "lattice_point_name" => "演示网点",
                            "lattice_point_no" => "900000",
                            "brand_name" => "",
                            "lattice_point_account_models" => [
                                [
                                    "brand_code" => "default",
                                    "recharge_quantity" => 100,
                                    "quantity" => 100,
                                    "lattice_point_no" => "900000",
                                    "recycled_quantity" => 0,
                                    "allocated_quantity" => 0,
                                    "segment_code" => "NORMAL",
                                    "confirm_quantity" => 0,
                                ],
                                [
                                    "brand_code" => "default",
                                    "recharge_quantity" => 100,
                                    "quantity" => 100,
                                    "lattice_point_no" => "900000",
                                    "recycled_quantity" => 0,
                                    "allocated_quantity" => 0,
                                    "segment_code" => "SVC-FRESH",
                                    "confirm_quantity" => 0,
                                ],
                            ],
                        ],
                        [
                            "brand_code" => "",
                            "delivery_address_models" => [],
                            "lattice_point_name" => "山东省市场部十部",
                            "lattice_point_no" => "250360",
                            "brand_name" => "",
                            "lattice_point_account_models" => [],
                        ],
                    ],
                    "express_name" => "韵达快递",
                    "logo" => "",
                    "express_biz_type" => 2,
                    "multi_brand" => false,
                ]
            ]
        ];
    }

    protected function youzan_logistics_waybill_get_print(Request $request)
    {
        $express_no = $request->get('express_no', '');

        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId(),
            "data" => [
                "express_no" => $express_no,
                "print_data" => "{\"encryptedData\":\"AES:rU904rj6UH2oqfSUb43+Z199vDU2GZtH5/LVIEq0ppUJuwjq7qZ58JRvDHOQ/f2QhqdsWiYYFqp6z96+fPLupxENx4gZUSA/zYJbbdwevCwYxJZTv3qwrG9IuZ5yj7dlDwwymeDusCq4X5pMpCN+KUNxMqQ/gCUW3Es19q0LZXk2653phsVs8a/YVC0Obge0ObMq+8N2PA30csOg4jLuOJCXlpE5ihsb1Vg9Il3LxKTvkJv15UUH3CxiFsHWPTkdYIwHALuWwG4aZhuSnT7B7O9l2s2xir4JSMT2+9hFY524TkFXb43he/tOyJoZJSDW1WbX5fQTrEQjwoei4tNdycnjJ5pMV3ySt2T2GczDcx00nKw+S+Fe34Zr4w6/lGqXiY/r2R1nWJCiaJcdHXUOvUjw9g+hbGTGvvKs1QEyJdAOHafelnhF9SRyist6ZQE0Ahknep82VORPY95qxZLqCSGGFGVMZ9S+pI4BtwZPVCinZ5Q7+iGjrkyr3nIoY7hCpMFQ2fK1GoosLS2Tr6lEcGeSwqJ7TdeGyLsJUI8RPgSmO9D5gBcGyQHyHIEKazjzOq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1EKHiKwIpTCHkxCbBPIzC3Jy3JiKGmqHzrnqBTob73YgKBNJnX9T0qLF94/rD56iOvFwO0h/LXVT5KFlR4X+x1IeWrCznanWxLy6/D04cEim1acxuW7STnuJR0UQ+ggso8alCpSPmlUContJUX+1MN1ShuVw59Mr2sIlIasYXnTDJLQ1tuCgXYT/lBkEfJMiy1mmDnwE/qcPh1/bYDRgRd+rzY5+Gl51qW3qZG8YWzXuLdxsZXno2aywnjvEe9KIM4gG38BC30GjW0p6fG2WjnoY9uSMDDScmmw/3NlNJA5EOhWKsWJlBNkOm3kzs81WX\",\"signature\":\"MD:SCeLKtFsV8w2gZDu+unWLw==\",\"templateURL\":\"http://cloudprint.cainiao.com/template/standard/401/198\",\"ver\":\"WB_V_1\"}",
            ]
        ];
    }

    protected function youzan_logistics_waybill_apply(Request $request)
    {
        $trade_order_info_list = $request->get('trade_order_info_list', []);

        $data = [];
        foreach ($trade_order_info_list as $i => $trade_order_info) {
            $apply_id = $trade_order_info['apply_id'] ?? '';
            $express_no = sprintf('XCXD_YOUZAN__%s_%s', date('YmdHis', time()), $i);
            $data[] = [
                "code" => 200,
                "success" => true,
                "message" => "success",
                "apply_id" => $apply_id,
                "express_no" => $express_no,
                "print_data" => "{\"encryptedData\":\"AES:rU904rj6UH2oqfSUb43+Z199vDU2GZtH5/LVIEq0ppUJuwjq7qZ58JRvDHOQ/f2QhqdsWiYYFqp6z96+fPLupxENx4gZUSA/zYJbbdwevCwYxJZTv3qwrG9IuZ5yj7dlDwwymeDusCq4X5pMpCN+KUNxMqQ/gCUW3Es19q0LZXk2653phsVs8a/YVC0Obge0ObMq+8N2PA30csOg4jLuOJCXlpE5ihsb1Vg9Il3LxKTvkJv15UUH3CxiFsHWPTkdYIwHALuWwG4aZhuSnT7B7O9l2s2xir4JSMT2+9hFY524TkFXb43he/tOyJoZJSDW1WbX5fQTrEQjwoei4tNdycnjJ5pMV3ySt2T2GczDcx00nKw+S+Fe34Zr4w6/lGqXiY/r2R1nWJC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jku57XbjCZHix+qB2D0i7EXc826G6Sf70BI03jEy64mhcP2eMiedxUlmIl3Nf4FxI9hfEFNzdiYhf3Bs/drB6g1vF5xg3zD+5KTkyYd8/1/j1aESs71/HpaCgIC0J7Zh/98OWkszlQVI5UmDNNbN4/x1fXndypbpC0c8Yv1bXugPVAU3qYPcoy/QBG1/T05l1EKHiKwIpTCHkxCbBPIzC3Jy3JiKGmqHzrnqBTob73YgKBNJnX9T0qLF94/rD56iOvFwO0h/LXVT5KFlR4X+x1IeWrCznanWxLy6/D04cEim1acxuW7STnuJR0UQ+ggso8alCpSPmlUContJUX+1MN1ShuVw59Mr2sIlIasYXnTDJLQ1tuCgXYT/lBkEfJMiy1mmDnwE/qcPh1/bYDRgRd+rzY5+Gl51qW3qZG8YWzXuLdxsZXno2aywnjvEe9KIM4gG38BC30GjW0p6fG2WjnoY9uSMDDScmmw/3NlNJA5EOhWKsWJlBNkOm3kzs81WX\",\"signature\":\"MD:SCeLKtFsV8w2gZDu+unWLw==\",\"templateURL\":\"http://cloudprint.cainiao.com/template/standard/401/198\",\"ver\":\"WB_V_1\"}",
            ];
        }

        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId(),
            "data" => $data
        ];
    }

    protected function youzan_logistics_waybill_update(Request $request)
    {
        $express_no = $request->get('express_no', '');

        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId(),
            "data" => [
                "code" => 200,
                "success" => true,
                "message" => "success",
                "apply_id" => 'xxx',
                "express_no" => $express_no,
                "print_data" => "{\"encryptedData\":\"AES:rU904rj6UH2oqfSUb43+Z199vDU2GZtH5/LVIEq0ppUJuwjq7qZ58JRvDHOQ/f2QhqdsWiYYFqp6z96+fPLupxENx4gZUSA/zYJbbdwevCwYxJZTv3qwrG9IuZ5yj7dlDwwymeDusCq4X5pMpCN+KUNxMqQ/gCUW3Es19q0LZXk2653phsVs8a/YVC0Obge0ObMq+8N2PA30csOg4jLuO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PDdxhShT6gQW7bRvi8DkuGFm76jvVxOTRGrOj4i9qGMK6gvPuI5A0D1RyU1RklO2+K9Ql0jK84WOgxvDPhqPWYE3dgbN7vGVRCU3Igha5y55c54MrhM0vktBvXBUjr8S1UsL1NCsjyNKdx++JYPQlyODX+td3Ltq4Eay/6O+wYKr3hAyZrzt+AUjku57XbjCZHix+qB2D0i7EXc826G6Sf70BI03jEy64mhcP2eMiedxUlmIl3Nf4FxI9hfEFNzdiYhf3Bs/drB6g1vF5xg3zD+5KTkyYd8/1/j1aESs71/HpaCgIC0J7Zh/98OWkszlQVI5UmDNNbN4/x1fXndypbpC0c8Yv1bXugPVAU3qYPcoy/QBG1/T05l1EKHiKwIpTCHkxCbBPIzC3Jy3JiKGmqHzrnqBTob73YgKBNJnX9T0qLF94/rD56iOvFwO0h/LXVT5KFlR4X+x1IeWrCznanWxLy6/D04cEim1acxuW7STnuJR0UQ+ggso8alCpSPmlUContJUX+1MN1ShuVw59Mr2sIlIasYXnTDJLQ1tuCgXYT/lBkEfJMiy1mmDnwE/qcPh1/bYDRgRd+rzY5+Gl51qW3qZG8YWzXuLdxsZXno2aywnjvEe9KIM4gG38BC30GjW0p6fG2WjnoY9uSMDDScmmw/3NlNJA5EOhWKsWJlBNkOm3kzs81WX\",\"signature\":\"MD:SCeLKtFsV8w2gZDu+unWLw==\",\"templateURL\":\"http://cloudprint.cainiao.com/template/standard/401/198\",\"ver\":\"WB_V_1\"}",
            ]
        ];
    }

    protected function youzan_logistics_waybill_delete(Request $request)
    {
        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "trace_id" => $this->_generateTraceId()
        ];
    }

    protected function youzan_appstore_open_user_get(Request $request)
    {
//        return [
//            "code" => 250700006,
//            "success" => false,
//            "message" => "userToken已过期，请尝试重新获取"
//        ];


        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "data" => [
                "kdt_id" => $this->authority_id,
                "code" => "4568df951558b6fca0e2d2eb91ff51c5",
                "phone" => "17816122521",
                "user_id" => 9735044406,
                "shop_role" => 0,
                "shop_type" => 0,
                "yz_open_id" => "riGGnexk699548718336069632",
                "shop_name" => "有料小分队200730",
                "app_id" => 46851
            ]
        ];
    }

    /**
     * 获取出售中的商品列表
     * @param Request $request
     * @return array
     */
    protected function youzan_items_onsale_get(Request $request)
    {
        $item = [
            "item_id" => 691664668,
            "page_url" => "packages/goods/detail/index",
            "is_virtual" => 3,
            "detail_url" => "https://h5.youzan.com/v2/showcase/goods?alias=2x7qqjwtq7f85",
            "share_detail" => 1100,
            "post_fee" => 0,
            "item_type" => 61,
            "num" => 0,
            "origin" => "",
            "channel" => 0,
            "title" => "qiao供货电子卡券商品",
            "update_time" => "2020-09-23 22:00:32",
            "price" => 1100,
            "alias" => "2x7qqjwtq7f85",
            "post_type" => 1,
            "barcode" => "",
            "created_time" => "2020-09-23 22:00:32",
            "image" => "https://img.yzcdn.cn/upload_files/2020/09/22/FjxqbnWqSZERlXAzpYf5aghEilCa.jpg?imageView2/0/w/240/h/240/q/75",
            "tag_ids" => [],
            "biz_code" => "000000000000",
            "quantity" => 332,
            "item_imgs" => [],
            "share_icon" => "https://img.yzcdn.cn/upload_files/2020/09/22/FjxqbnWqSZERlXAzpYf5aghEilCa.jpg?imageView2/0/w/240/h/240/q/75",
            "classid" => "youzan_goods_selling",
            "item_source" => 0,
            "goods_platform" => 0,
            "actual_quantity" => "332",
            "share_title" => "qiao供货电子卡券商品",
            "root_item_id" => 0,
            "delivery_template" => [],
            "root_kdt_id" => 0,
            "video_id" => 0,
            "ability_mark_codes" => []
        ];

        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "data" => [
                "count" => 1,
                "items" => [
                    $item
                ],
            ]
        ];
    }

    /**
     * 查询单商品明细接口
     * @param Request $request
     * @return array
     */
    protected function youzan_item_detail_get(Request $request)
    {
        $item = [
            "sku_no" => "MINI20-HGDGPJH",
            "price" => 23000,
            "stock_num" => 7,
            "sku_created_time" => 1737525416000,
            "sku_id" => 25780981030,
            "sku_barcode" => "",
            "sku_modified_time" => 1738634352000,
            "sku_props" => [
                [
                    "prop_name" => "限时组合",
                    "prop_value_id" => 546746364,
                    "prop_value_name" => "白边20张+海格蛋糕配件盒（含10张爱心相纸）",
                    "prop_name_id" => 51685789
                ]
            ],
            "sold_num" => 13
        ];

        return [
            "code" => 200,
            "success" => true,
            "message" => "success",
            "data" => [
                "cid" => 0,
                "display" => 1,
                "item_no" => "MINI20-HGDGPJH",
                "title" => "【相纸周边限时组合】富士 instax 白边相纸 20张套组",
                "sku_list" => [
                    $item
                ],
                "hide_stock" => 1,
                "post_sale_param" => [],
                "item_type" => 0,
                "channel" => 0,
                "category_properties" => [],
                "item_barcode" => "",
                "need_customs_check" => false,
                "created_time" => 1731546358000,
                "tag_ids" => [],
                "images" => [],
                "biz_code" => "000000000000",
                "sku_picture_display_config" => true,
                "purchase_permission" => [],
                "stock_deduct_mode" => 0,
                "item_delivery_param" => [],
                "goods_platform" => 0,
                "channels" => [],
                "spu" => [],
                "messages" => [],
                "root_item_id" => 0,
                "item_page_setting_model" => [],
                "root_kdt_id" => 0,
                "extra_param" => [],
                "desc" => "<p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/FmJEZDAtRqS_vtScv7_z8p6lOQSp.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/FmAN8gqOJwpbxgqW3ewQ7xxkMNrD.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/FtRYSzhezKhnu9zJH-Kpoic8lDWv.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/FhhK7GNXjHMvMRzZr57v0esk9X4p.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/Foa6mqkjINAN4xx1I6nfRxEQ24fZ.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/FlAVwDmR1ppVl1sc9fvEMMoHNAII.jpg\" /></p><p style=\"margin:0px;\"><img src=\"https://img01.yzcdn.cn/upload_files/2024/06/26/Fr9CJkXEuPoKbMX9RXTb0lWJYaEW.jpg\" /></p>",
                "ability_mark_codes" => [],
                "item_props" => [],
                "is_virtual" => 0,
                "template" => [],
                "detail_url" => "https://h5.youzan.com/v2/showcase/goods?alias=1yj8mbpylxvvxcp&from=wsc&kdtfrom=wsc",
                "auto_listing_time" => 0,
                "item_price_param" => [],
                "join_level_discount" => false,
                "buy_btn_label" => "",
                "actual_tag_ids" => [],
                "kdt_id" => 108029901,
                "is_serial_item" => 0,
                "alias" => "1yj8mbpylxvvxcp",
                "need_customs_info" => false,
                "summary" => "",
                "need_customs_info_with_picture" => false,
                "quantity" => 59,
                "is_multi_unit_item" => 0,
                "item_id" => 3580532748,
                "sku_value_props" => [],
                "sold_num" => 2681,
                "size_group" => [],
                "buy_btn_config" => 0,
                "start_sale_num" => 1,
                "sell_point" => "单包mini白边相纸组合装",
                "video_id" => 0
            ]
        ];
    }
}
